const init = (vm) => {
	//需要确认的弹窗消息
	vm.prototype.$confirm = (msg) => {
		//异步转同步
		return new Promise((resolve, reject) => {
			uni.showModal({
				title: '温馨提示',
				content: msg,
				cancelText: '取消',
				confirmText: '确定',
				success: function(res) {
					if (res.confirm) {
						resolve(res.confirm)
					} else {
						resolve(false)
					}
				},

			})
		})
	}
}

export default {
	success(msg, delta, url) {
		uni.showToast({
			title: msg,
			icon: 'success',
			success() {
				setTimeout(() => {
					if (delta) {
						uni.navigateBack({
							delta: delta || 1
						})
					} else if (url) {
						uni.navigateTo({
							url: url
						})
					} else {
						window.location.reload()
					}
				}, 1500)
			}
		})
	},
	error(msg) {
		uni.showToast({
			title: msg,
			icon: 'error'
		})
	},
	alert(msg) {
		uni.showModal({
			title: '提示',
			content: msg,
			showCancel: false
		})
	},
	default (msg, delta, url) {
		uni.showToast({
			title: msg,
			icon: 'none',
			success() {
				setTimeout(() => {
					if (delta) {
						uni.navigateBack({
							delta: delta || 1
						})
					} else if (url) {
						uni.navigateTo({
							url: url
						})
					} else {
						window.location.reload()
					}
				}, 1500)
			}
		})
	},
	init
}
